import ejs from "ejs";
import fs from "fs";
import {resolve} from "path";
import prettier from "prettier";
import {dirname} from "./utils/es-dirname.mjs";

export default (config) => {
  const templateCode = fs.readFileSync(
    resolve(dirname(import.meta), "./template/package.ejs"),
    "utf8"
  );
  const code = ejs.render(templateCode, {
    pkgName: config.name,
    pkgDesc: config.description,
    pkgVersion: config.version,
    pkgAuthor: config.author,
  });

  console.log(code);

  return prettier.format(code, {parser: "json"});
};
